package com.example.module_maintenance

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.example.module_maintenance.adapter.VisitorAdapter
import com.example.module_maintenance.databinding.ActivityMaintenBinding
import com.example.module_maintenance.viewmodel.MaintenanceViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.PATH_MAINTENANCE_ACTIVITY)
class MaintenanceActivity : BaseActivity<ActivityMaintenBinding>() {

    private val vm by lazy { ViewModelProvider(this)[MaintenanceViewModel::class.java] }
    private val visitorAdapter by lazy { VisitorAdapter() }

    override fun initView() {
        mDataBinding.visitorManagementList.adapter = visitorAdapter
        mDataBinding.visitorManagementList.layoutManager = LinearLayoutManager(this)
        vm.getVisitors()

        vm.getVisitorsSuccess.observe(this){
            visitorAdapter.data.clear()
            visitorAdapter.data.addAll(it)
            visitorAdapter.notifyDataSetChanged()
        }
       mDataBinding.visitorManagerAdd.setOnClickListener {
           ARouter.getInstance().build(RouterPath.PATH_ADD_VISITOR_ACTIVITY).navigation()
       }
        mDataBinding.visitorManagerBack.setOnClickListener {
            finish()
        }


    }





    override fun getLayoutId(): Int = R.layout.activity_mainten
}


